<!DOCTYPE html>
<html lang="zh">
<head>
    <title>权限管理 - virus CMS</title>
    {include file="common/meta" /}
</head>
<body>

<!-- Navbar -->
{include file="common/header" /}
<!-- /Navbar -->
<!-- Main Container -->
<div class="main-container container-fluid">
    <!-- Page Container -->
    <div class="page-container">

        <!-- Page Sidebar -->
        {include file="common/sidebar" /}
        <!-- /Page Sidebar -->
        <!-- Page Content -->
        <div class="page-content">
            <!-- Page Breadcrumb -->
            <div class="page-breadcrumbs">
                <ul class="breadcrumb">
                    <li class="active">
                        <i class="fa fa-home"></i>&nbsp;控制面板
                    </li>
                    <li>
                        <i class="fa fa-cogs"></i> 常规管理
                    </li>
                    <li>
                        <i class=""></i> 权限管理
                    </li>
                </ul>
            </div>
            <!-- /Page Breadcrumb -->
            <!-- Page Body -->
            <div class="page-body">
                <div class="row">
                    <div class="col-lg-12 col-sm-12 col-xs-12">
                        <div class="widget flat radius-bordered">
                            <div class="widget-header bg-themeprimary">
                                <span class="widget-caption"><i class="fa fa-plus"></i>添加权限</span>
                            </div>

                            <div class="widget-body">
                                <div class="widget-main ">
                                    <form class="form-horizontal">
                                        <div class="form-group">
                                            <div class="form-group">
                                                <label for="pid" class="col-sm-2 control-label no-padding-right">父级权限</label>
                                                <div class="col-sm-6">
                                                    <select name="pid" required id="pid" class="form-control">
                                                        <option value="0" {if condition="$rule_one.pid eq 0"}selected{/if}>顶级权限</option>
                                                        {foreach $all_top_permissions as $v}
                                                            <option value="{$v.id}" {if condition="$rule_one.pid eq $v.id"}selected{/if}>{$v.title_display}</option>
                                                        {/foreach}
                                                    </select>
                                                </div>
                                            </div>
                                            <input type="hidden" name="id" value="{$rule_one.id}">
                                            <div class="form-group">
                                                <label for="name" class="col-sm-2 control-label no-padding-right">权限规则</label>
                                                <div class="col-sm-6">
                                                    <input type="text" name="name" id="name" class="form-control" value="{$rule_one.name}">
                                                </div>
                                            </div>
                                            <div class="form-group">
                                                <label for="title" class="col-sm-2 control-label no-padding-right">权限标题</label>
                                                <div class="col-sm-6">
                                                    <input type="text" name="title" id="title" class="form-control" value="{$rule_one.title}">
                                                </div>
                                            </div>
                                            <div class="form-group">
                                                <label for="type" class="col-sm-2 control-label no-padding-right">权限类型</label>
                                                <div class="col-sm-6">
                                                    <select name="type" id="type" class="form-control">
                                                        <option value="1" {if condition="$rule_one.type eq 1"}selected{/if}>模块</option>
                                                        <option value="2" {if condition="$rule_one.type eq 2"}selected{/if}>操作</option>
                                                    </select>
                                                </div>
                                            </div>
                                            <div class="form-group">
                                                <label for="condition" class="col-sm-2 control-label no-padding-right">附加条件</label>
                                                <div class="col-sm-6">
                                                    <input type="text" name="condition" id="condition" class="form-control" value="{$rule_one.condition}">
                                                </div>
                                            </div>
                                            <div class="form-group">
                                                <label for="icon" class="col-sm-2 control-label no-padding-right">图标</label>
                                                <div class="col-sm-6">
                                                    <input type="text" name="icon" id="icon" class="form-control" value="{$rule_one.icon}">
                                                </div>
                                            </div>
                                            <div class="form-group">
                                                <label class="col-sm-2 control-label no-padding-right">是否是菜单</label>
                                                <div class="col-sm-6">
                                                    <div class="radio">
                                                        <label>
                                                            <input type="radio" name="is_menu" value="1" {if condition="$rule_one.is_menu eq 1"}checked{/if}>
                                                            <span class="text">是</span>
                                                        </label>
                                                        <label>
                                                            <input type="radio" name="is_menu" value="0" {if condition="$rule_one.is_menu eq 0"}checked{/if}>
                                                            <span class="text">否</span>
                                                        </label>
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="form-group">
                                                <label class="col-sm-2 control-label no-padding-right">状态</label>
                                                <div class="col-sm-6">
                                                    <div class="radio">
                                                        <label>
                                                            <input type="radio" name="status" value="1" {if condition="$rule_one.status eq 1"}checked{/if}>
                                                            <span class="text">开启</span>
                                                        </label>
                                                        <label>
                                                            <input type="radio" name="status" value="0" {if condition="$rule_one.status eq 0"}checked{/if}>
                                                            <span class="text">禁用</span>
                                                        </label>
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="form-group">
                                                <div class="col-sm-offset-2 col-sm-10">
                                                    <button type="button" id="addPermission"
                                                            class="btn btn-primary">确定
                                                    </button>
                                                </div>
                                            </div>
                                        </div>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!-- /Page Body -->
        </div>
        <!-- /Page Content -->

    </div>
    <!-- /Page Container -->
    <!-- Main Container -->

</div>

{include file="common/script" /}
<script type="text/javascript">
    $(function () {
        $('#addPermission').click(function () {
            // 前端参数判断
            let name = $('#name').val();
            let title = $('#title').val();
            if (name === "" || title === "") {
                toastr.error("参数不能为空");
                return false;
            }

            url = '/admin/Rule/update';
            $.ajax({
                data: $('form').serialize(),
                type: "POST",
                url: url,
                dataType: 'json',
                success: (data) => {
                    if (data.code === 1) {
                        toastr.success(data.msg);
                        setTimeout(function () {
                            location.href = '/admin/Rule/index';
                        }, 2000);
                    } else {
                        toastr.error(data.msg);
                    }
                }
            });
            return false;
        });
    });
</script>
</body>
<!--  /Body -->
</html>
